package com.cskaoyan.controller.admin.promotion;

import com.cskaoyan.anno.ValidAnno;
import com.cskaoyan.bean.MarketTopic;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO;
import com.cskaoyan.bean.vo.admin.promotion.AdminTopicAndGoodsVO;
import com.cskaoyan.bean.vo.admin.promotion.AdminTopicVO;
import com.cskaoyan.service.admin.promotion.AdminTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/*
 * @Auther:王贲
 * @Date:2022/9/7
 * @Description:
 * @VERSON:1.8
 */
@RestController
@RequestMapping("admin/topic")
public class AdminTopicController {

    @Autowired
    AdminTopicService adminTopicService;

    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 专题页面的显示与模糊查询
     * @author wang'ben
     * @date 2022/9/7 21:03
     */
    @RequestMapping("list")
    public BaseRespVo listTopic(BasePageInfo basePageInfo, String title, String subtitle) {
        CommonData commonData = adminTopicService.selectTopicInfo(basePageInfo, title, subtitle);

        return BaseRespVo.ok(commonData);
    }

    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 添加专题
     * @author wang'ben
     * @date 2022/9/7 21:06
     */
    @PostMapping("create")
    @ValidAnno
    public BaseRespVo createTopic(@RequestBody@Valid MarketTopic marketTopic, BindingResult bindingResult) {
        adminTopicService.insertTopicInfo(marketTopic);
        return BaseRespVo.ok(marketTopic);
    }


    /**
     * @return com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO
     * @description : TODO 专题的删除
     * @author wang'ben
     * @date 2022/9/7 23:05
     */
    @PostMapping("delete")
    public AdminAdDeleteVO deleteTopic(@RequestBody MarketTopic marketTopic) {
        adminTopicService.deleteTopicInfo(marketTopic);
        return AdminAdDeleteVO.ok("成功");
    }

    /**
     * @description : TODO 专题页面批量删除
     * @return com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO
     * @author wang'ben
     * @date 2022/9/7 23:42
     */
    @PostMapping("batch-delete")
    public AdminAdDeleteVO batchDeleteTopic(@RequestBody AdminTopicVO adminTopicVO) {
        adminTopicService.batcheDeleteInfo(adminTopicVO);
        // adminTopicService.batcheDeleteInfo(ids);
        return AdminAdDeleteVO.ok("成功");
    }


    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 进入编辑
     * @author wang'ben
     * @date 2022/9/8 12:00
     */
    @GetMapping("read")
    public BaseRespVo readTopic(Integer id) {
        AdminTopicAndGoodsVO adminTopicAndGoodsVO = adminTopicService.updateTopicInfo(id);
        return BaseRespVo.ok(adminTopicAndGoodsVO);
    }


    @PostMapping("update")
    public BaseRespVo updateTopic(@RequestBody MarketTopic marketTopic) {
        adminTopicService.updateTopic(marketTopic);
        return BaseRespVo.ok(marketTopic);
    }
}
